import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/hire/api/hireApi.dart';
import 'package:honeypotflutter/modules/hire/views/hire_empty_item.dart';
import 'package:honeypotflutter/public/public_get.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/public/views/public_refresh.dart';
import '../../models/hire_empty_model.dart';
import '../hire_rent_rent/view.dart';
import 'logic.dart';

class HireEmptyPage extends StatefulWidget {
  final int? source;
  const HireEmptyPage({
    Key? key,
    this.source,
  }) : super(key: key);

  @override
  State<HireEmptyPage> createState() => _HireEmptyPageState();
}

class _HireEmptyPageState extends State<HireEmptyPage> {
  final HireEmptyLogic logic = Get.put(HireEmptyLogic());
  HLRefreshController refreshController = HLRefreshController(initialRefresh: true);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: (widget.source == 1) ? null : HLAppBar(navigationTitle: "空箱查询"),
      body: HLRefresh<HireEmptyModel>(
          isLoading: false,
          refreshController: refreshController,
          onRefresh: () {
            return HireApi.emptyList();
          },
          snap: (itemModel, int index) {
            return HireEmptyItem(
                itemModel: itemModel,
                rentAction: () {
                  this.pushToRentInfo(itemModel);
                });
          }),
    );
  }

  /*
  * 去租赁
  * */
  pushToRentInfo(HireEmptyModel itemModel) async {
    bool result = await HLGet.to(HireRentRentPage(), arguments: itemModel);
    if (result) {
      refreshController.requestRefresh();
    }
  }

  @override
  void dispose() {
    Get.delete<HireEmptyLogic>();
    super.dispose();
  }
}
